#!/bin/bash

# 生成四个不同模式的 wolfssl 种子
# 1. TLS 1.2 oneway
# 2. TLS 1.2 mutual
# 3. TLS 1.3 oneway
# 4. TLS 1.3 mutual

BASE_DIR="/home/ubuntu/experiments/out-wolfssl-pyafl/tlsfuzzer"
HOST="127.0.0.1"

echo "=========================================="
echo "开始生成 wolfssl 种子文件"
echo "=========================================="

# 1. TLS 1.2 oneway
echo ""
echo "[1/4] 生成 TLS 1.2 oneway 种子..."
python3 /home/ubuntu/llmafl/generate_seeds.py \
    --server-cmd "/home/ubuntu/experiments/wolfssl/build/examples/server/server --root /home/ubuntu/experiments/wolfssl -p 4433 -x -g -i -r -v 3 --fix-random -k /home/ubuntu/experiments/certs/server-key.pem -c /home/ubuntu/experiments/certs/server-cert.pem -d" \
    --save-dir "${BASE_DIR}/tls12-oneway/save" \
    --seeds-dir "${BASE_DIR}/tls12-oneway/seeds" \
    --host "${HOST}" \
    --port 4433

# 2. TLS 1.2 mutual
echo ""
echo "[2/4] 生成 TLS 1.2 mutual 种子..."
python3 /home/ubuntu/llmafl/generate_seeds.py \
    --server-cmd "/home/ubuntu/experiments/wolfssl/build/examples/server/server --root /home/ubuntu/experiments/wolfssl -p 4434 -x -g -i -r -v 3 --fix-random -k /home/ubuntu/experiments/certs/server-key.pem -c /home/ubuntu/experiments/certs/server-cert.pem -A /home/ubuntu/experiments/certs/ca-cert.pem" \
    --save-dir "${BASE_DIR}/tls12-mutual/save" \
    --seeds-dir "${BASE_DIR}/tls12-mutual/seeds" \
    --host "${HOST}" \
    --port 4434

# 3. TLS 1.3 oneway
echo ""
echo "[3/4] 生成 TLS 1.3 oneway 种子..."
python3 /home/ubuntu/llmafl/generate_seeds.py \
    --server-cmd "/home/ubuntu/experiments/wolfssl/build/examples/server/server --root /home/ubuntu/experiments/wolfssl -p 4435 -x -g -i -r -v 4 --fix-random -k /home/ubuntu/experiments/certs/server-key.pem -c /home/ubuntu/experiments/certs/server-cert.pem -d" \
    --save-dir "${BASE_DIR}/tls13-oneway/save" \
    --seeds-dir "${BASE_DIR}/tls13-oneway/seeds" \
    --host "${HOST}" \
    --port 4435

# 4. TLS 1.3 mutual
echo ""
echo "[4/4] 生成 TLS 1.3 mutual 种子..."
python3 /home/ubuntu/llmafl/generate_seeds.py \
    --server-cmd "/home/ubuntu/experiments/wolfssl/build/examples/server/server --root /home/ubuntu/experiments/wolfssl -p 4436 -x -g -i -r -v 4 --fix-random -k /home/ubuntu/experiments/certs/server-key.pem -c /home/ubuntu/experiments/certs/server-cert.pem -A /home/ubuntu/experiments/certs/ca-cert.pem" \
    --save-dir "${BASE_DIR}/tls13-mutual/save" \
    --seeds-dir "${BASE_DIR}/tls13-mutual/seeds" \
    --host "${HOST}" \
    --port 4436

echo ""
echo "=========================================="
echo "所有种子生成完成！"
echo "种子保存目录:"
echo "  - TLS 1.2 oneway: ${BASE_DIR}/tls12-oneway/seeds"
echo "  - TLS 1.2 mutual: ${BASE_DIR}/tls12-mutual/seeds"
echo "  - TLS 1.3 oneway: ${BASE_DIR}/tls13-oneway/seeds"
echo "  - TLS 1.3 mutual: ${BASE_DIR}/tls13-mutual/seeds"
echo "=========================================="
